/*
 *   Copyright (c) 2010-2022, SIUFUNG
 */
package net.siufung.market.base.app.controller.model.app;

import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.siufung.core.model.AbstractVo;
import net.siufung.core.model.enums.DefaultEnum;
import net.siufung.core.model.enums.DeletedEnum;

import java.time.LocalDateTime;

/**
 * @author 陈建峰
 * @date 2023-01-12 16:24:13
 * @since v1.0.0
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value="AppVo", description="应用信息")
public class AppVo extends AbstractVo {

    private static final long serialVersionUID = 6833371050295542523L;
    /**
     * 主键ID
     */
    @ApiModelProperty(value = "主键ID")
    private Integer id;

    /**
     * 应用名称
     */
    @ApiModelProperty(value = "应用名称")
    private String appName;

    /**
     * 应用编码
     */
    @ApiModelProperty(value = "应用编码")
    private String appCode;

    /**
     * 应用logo
     */
    @ApiModelProperty(value = "应用logo")
    private String appIcon;

    /**
     * 应用类型
     */
    @ApiModelProperty(value = "应用类型")
    private String appType;

    /**
     * 访问路径
     */
    @ApiModelProperty(value = "访问路径")
    private String appPath;

    /**
     * 客户端ID
     */
    @ApiModelProperty(value = "客户端ID")
    private String clientId;

    /**
     * 客户端密钥
     */
    @ApiModelProperty(value = "客户端密钥")
    private String clientSecret;

    /**
     * 权限范围
     */
    @ApiModelProperty(value = "权限范围")
    private String clientScope;

    /**
     * 客户端支持的授权方式
     */
    @ApiModelProperty(value = "客户端支持的授权方式")
    private String clientGrantTypes;

    /**
     * 访问令牌有效时间值(单位:秒)
     */
    @ApiModelProperty(value = "访问令牌有效时间值(单位:秒)")
    private Integer accessTokenSec;

    /**
     * 更新令牌有效时间值(单位:秒)
     */
    @ApiModelProperty(value = "更新令牌有效时间值(单位:秒)")
    private Integer refreshTokenSec;

    /**
     * 是否默认
     */
    @ApiModelProperty(value = "是否默认")
    private boolean defaultFlag;

    /**
     * 应用描述
     */
    @ApiModelProperty(value = "应用描述")
    private String description;

    /**
     * 租户
     */
    @ApiModelProperty(value = "租户")
    private String tenantId;

    /**
     * 创建人
     */
    @ApiModelProperty(value = "创建人")
    private String createdBy;

    /**
     * 创建时间
     */
    @ApiModelProperty(value = "创建时间")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    private LocalDateTime createdAt;

    /**
     * 更新人
     */
    @ApiModelProperty(value = "更新人")
    private String updatedBy;

    /**
     * 更新时间
     */
    @ApiModelProperty(value = "更新时间")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    private LocalDateTime updatedAt;

    /**
     * 数据标识
     */
    @ApiModelProperty(value = "数据标识")
    private Boolean deleted;

    /**
     * 是否默认
     * @return String
     */
    public String getDefaultFlagDesc() {
        return DefaultEnum.getDesc(this.defaultFlag);
    }

    @Override
    public boolean getAllowRemove() {
        return DeletedEnum.NOT.equals(DeletedEnum.get(deleted))
                && DefaultEnum.NOT.equals(DefaultEnum.get(this.defaultFlag));
    }

    @Override
    public boolean getAllowUpdate() {
        return DeletedEnum.NOT.equals(DeletedEnum.get(deleted))
                && DefaultEnum.NOT.equals(DefaultEnum.get(this.defaultFlag));
    }

    @Override
    public boolean getAllowStatus() {
        return DefaultEnum.NOT.equals(DefaultEnum.get(this.defaultFlag));
    }

    public boolean getAllowBindMenu(){
        return DefaultEnum.NOT.equals(DefaultEnum.get(this.defaultFlag));
    }
}